package com.example.skudemo.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 定义数据返回包装类
 *
 */
public class ApiResult extends HashMap<String, Object> {
    public ApiResult() {
        put("code", 0);
        put("message", "成功");
    }

    public static ApiResult error() {
        return error(1, "未知错误");
    }

    public static ApiResult error(String message) {
        return error(1, message);
    }

    public static ApiResult error(int code, String message) {
        ApiResult apiResult = new ApiResult();
        apiResult.put("code", code);
        apiResult.put("message", message);
        return apiResult;
    }

    public static ApiResult error(String message, String method, String url) {
        ApiResult apiResult = new ApiResult();
        apiResult.put("code", 1);
        apiResult.put("message", message);
        apiResult.put("method", method);
        apiResult.put("url", url);
        return apiResult;
    }

    public static ApiResult error(int code, String message, String method, String url) {
        ApiResult apiResult = new ApiResult();
        apiResult.put("code", code);
        apiResult.put("message", message);
        apiResult.put("method", method);
        apiResult.put("url", url);
        return apiResult;
    }

    public static ApiResult success() {
        return new ApiResult();
    }

    public static ApiResult success(String message) {
        ApiResult apiResult = new ApiResult();
        apiResult.put("message", message);
        return apiResult;
    }

    public static ApiResult success(Map<String, Object> map) {
        ApiResult apiResult = new ApiResult();
        apiResult.put("result", map);
        return apiResult;
    }

    public static  ApiResult success(Object data) {
        ApiResult apiResult = new ApiResult();
        apiResult.put("result", data);
        return apiResult;
    }

    public static  ApiResult success(Object data, String message) {
        ApiResult apiResult = new ApiResult();
        apiResult.put("message", message);
        apiResult.put("result", data);
        return apiResult;
    }

    public static  ApiResult success(Object data, String message, Integer code) {
        ApiResult apiResult = new ApiResult();
        apiResult.put("code", code);
        apiResult.put("message", message);
        apiResult.put("result", data);
        return apiResult;
    }

    public ApiResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
